//
//  GifCollectionViewCell.m
//  GIFShow
//
//  Created by lanou11air029 on 15/5/1.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "GifCollectionViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <UIImageView+PlayGIF.h>
@interface GifCollectionViewCell ()
@property (nonatomic, strong) UIImageView * gifView;
@property (nonatomic, strong) UILabel * title;
@end
@implementation GifCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.gifView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        self.gifView.contentMode = UIViewContentModeScaleAspectFill;
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(2, frame.size.height-25, frame.size.width-4, 21)];
        self.title.textColor = [UIColor whiteColor];
        self.title.shadowColor = [UIColor blackColor];
        self.title.shadowOffset = CGSizeMake(1, 1);
        [self.contentView addSubview:self.gifView];
        [self.contentView addSubview:self.title];
        self.gifView.clipsToBounds = YES;
        self.contentView.clipsToBounds = YES;
    }
    return self;
}
-(void)setGifItem:(GifDownload *)gifItem{
    if (_gifItem != gifItem) {
        _gifItem = gifItem;
        NSString * file = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
        NSString * filePath = [file stringByAppendingPathComponent:gifItem.art_id];
        NSData * data = [NSData dataWithContentsOfFile:filePath];
        self.gifView.gifData = data;
        [self.gifView startGIF];
        
        
        self.title.text = gifItem.content;
        [self.gifView startAnimating];// [self.gifView startGif];
    }
}
@end
